package com.zpz.framework.zpzoauth.config.exception;

import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultMsg;
import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultStatus;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ErrorController{
    /**
     * 重新抛出异常
     */
    @RequestMapping("/error/exthrow")
    public ResponseEntity<ZpzOauthResultMsg<Object>> rethrow(HttpServletRequest request) {
        String error = request.getAttribute("error").toString();
        ZpzOauthResultMsg<Object> re = ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.EXCEPTION, error);
        re.setMessage(error);
        return new ResponseEntity<ZpzOauthResultMsg<Object>>(re, HttpStatus.OK);
    }
}
